package leetcode;

import java.math.BigInteger;

public class Lc67 {


    public String addBinary(String a, String b) {
        StringBuffer buff = new StringBuffer();
        boolean carry = false;
        int alen = a.length() - 1;
        int blen = b.length() - 1;
        while (alen >= 0 && blen >= 0) {
            if (a.charAt(alen) == '0' && b.charAt(blen) == '0') {
                buff.append(carry == true ? '1' : '0');
                carry = false;
            } else if (a.charAt(alen) == '1' && b.charAt(blen) == '1') {
                buff.append(carry == true ? '1' : '0');
                carry = true;
            } else {
                buff.append(carry == true ? '0' : '1');
            }
            alen--;
            blen--;
        }
        while (alen >= 0) {
            if (a.charAt(alen) == '0') {
                buff.append(carry == true ? '1' : '0');
                carry = false;
            } else {
                buff.append(carry == true ? '0' : '1');
            }
            alen--;
        }
        while (blen >= 0) {
            if (b.charAt(blen) == '0') {
                buff.append(carry == true ? '1' : '0');
                carry = false;
            } else {
                buff.append(carry == true ? '0' : '1');
            }
            blen--;
        }
        if (carry)
            buff.append('1');
        return buff.reverse().toString();
    }


    public static void main(String[] args) {
        String s = "1010";
        String s2 = "1011";
        Lc67 lc67 = new Lc67();
        System.out.println(lc67.addBinary(s, s2));

        System.out.println(5 | 1);

    }








}
